package com.luban;


import com.luban.registar.LubanBeanRegistar;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

//@ComponentScan("com.luban")
//@Import(LubanBeanRegistar.class)
//@Configuration
//@MapperScan("com.luban.dao")

public class MapperConfig {


	/**
	 * 2.0版本多了一个配制方式 可以不用使用MapperScan 直接定义一个MapperScancerConfigurer的Bean
	 * @return
	 */
//	@Bean
//	public MapperScannerConfigurer configurer() {
//		MapperScannerConfigurer configurer= new MapperScannerConfigurer();
//		configurer.setBasePackage("com.luban.dao");
//		return configurer;
//	}
//
//	@Bean
//	public DataSource dataSource() {
//		DriverManagerDataSource dataSource = new DriverManagerDataSource();
//		dataSource.setUrl("jdbc:mysql://localhost:33306/luban");
//		dataSource.setUsername("root");
//		dataSource.setPassword("123456");
//
//
//		try {
//			Connection connection = dataSource.getConnection();
//			PreparedStatement insert = connection.prepareStatement("insert");
//			insert.execute();
//			connection.commit();
//		} catch (SQLException e) {
//			e.printStackTrace();
//		}
//
//		return dataSource;
//	}
//
//	@Bean
//	public SqlSessionFactoryBean sqlSessionFactory() {
//		SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
//		sessionFactoryBean.setDataSource(dataSource());
//		try {
//			sessionFactoryBean.setConfigurationProperties(PropertiesLoaderUtils.loadAllProperties("db.properties"));
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		return sessionFactoryBean;
//	}


}
